class Permission {
  final int id;
  final int? parentId;
  final String name;
  final String type;
  final String code;
  final String remark;
  final bool isSelected;

  Permission({
    required this.id,
    required this.parentId,
    required this.name,
    required this.type,
    required this.code,
    required this.remark,
    this.isSelected = false,
  });

  factory Permission.fromJson(Map<String, dynamic> json) {
    var p =  Permission(
      id: json['id'] as int,
      parentId: (json['parent_id'] ?? 0) as int,
      name: json['name'] as String,
      type: json['type'] as String,
      code: json['code'] as String,
      remark: json['remark'] as String,
      isSelected: (json['is_selected'] ?? false) as bool? ?? false,
    );

    return p;
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'parentId': parentId,
      'name': name,
      'type': type,
      'code': code,
      'remark': remark,
      'is_selected': isSelected,
    };
  }

  Permission copyWith({
    int? id,
    int? parentId,
    String? name,
    String? type,
    String? code,
    String? remark,
    bool? isSelected,
  }) {
    return Permission(
      id: id ?? this.id,
      parentId: parentId ?? this.parentId,
      name: name ?? this.name,
      type: type ?? this.type,
      code: code ?? this.code,
      remark: remark ?? this.remark,
      isSelected: isSelected ?? this.isSelected,
    );
  }
}
